package com.mrs.service.impl;

import com.mrs.utils.SecurityUtils;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * description: PermissionService
 * date: 2022/9/12 20:52
 * author: MR.孙
 */
@Service("ps")
public class PermissionService {

    public Boolean hasPermissons(String permission){
        //获取用户的权限列表

        //1. 如果参数是admin用户直接返回true
        if(SecurityUtils.isAdmin()){
            return true;
        }

        //2. 判断参数是否在权限列表中
        List<String> permissions = SecurityUtils.getLoginUser().getPermissions();

       return permissions.contains(permission);

    }
}
